<template>
  <div class="app-container home bg-grey">

    <el-row :gutter="20">

      <el-col :sm="24" :lg="24" class="bg-fff bor-r-10 p20 mb20">
        <h2 style="color:#777;font-size: 20px;">身心财健康科技 & 要美丽要健康</h2>
        <p>

        </p>
        <p>
          <b>当前版本:</b> <span>v{{ version }}</span>
        </p>
        <p>
          <b>销售人员主页</b>
        </p>
      </el-col>

    </el-row>



    <el-row justify="center" :gutter="10">
      <el-col :xs="24" :sm="24">
        <div class="bg-fff bor-r-5 p20 mb20">
          <UserInfoCard />
        </div>
      </el-col>

      <el-col :xs="24" :sm="24" :md="12" :lg="10" :xl="8">
        <div class="bg-fff bor-r-5 p20 mb20">
          <UsefulLinks />
        </div>
      </el-col>

      <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">

        <div class="bg-fff bor-r-5 p20 mb20">

          <div class="pb15">设备使用情况</div>
          <div ref="usedmemory" style="height: 420px" />
        </div>
      </el-col>


      <!-- <el-col :xs="24" :sm="24" :md="8" :lg="6" :xl="4">
          <QrCode :url="qrUrl" title="顾客扫描二维码" :isDown="true" :isEdit="false" @edit="" />
      </el-col> -->

    </el-row>







  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getUserProfile } from "@/api/system/user";
import { getCache } from "@/api/monitor/cache";
import * as echarts from "echarts";

import UsefulLinks from './home/UsefulLinks.vue';
import UserInfoCard from './home/UserInfoCard.vue';
import QrCode from "./components/QrCode.vue";


export default {
  name: "adminHome",
  components: { UsefulLinks, UserInfoCard, QrCode },
  data() {
    return {
      // 版本号
      version: "1.3.1",
      configList: [],
      usedmemory: null,
      qrUrl: '',
      user: {},
      roleGroup: {},
      postGroup: {},


      // 查询参数
      queryP: {
        pageNum: 1,
        offset: 0,
        limit: 12,
        name: "",
        graphId: "retrieval_graph",
        metadata: {},
      },
    };
  },
  computed: {
    ...mapGetters(["sidebarRouters", "sidebar", "avatar"]),
  },
  mounted() {

    this.getUser();
    this.getCfgList();
    this.getCacheList();


  },
  // zz.25.11.28 商户配置助手信息
  watch: {
    meirongKey: { // 监听 meirongKey 的变化
      handler() {
        this.setConfigApi();
      },
      deep: false, // 是否深度监听（json...）
    },
  },
  methods: {

    comfirms(item) {
      this.$confirm('是否修改当前账户下所有销售助手配置为：'+item.name+'，请谨慎操作', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.meirongKey = item.assistant_id
        this.$message({
          type: 'success',
          message: '修改配置成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },

    checkOut(item) {
      if (!item.assisId) {
        this.$modal.msgError("当前模块未配置对应助手");
        return false
      }
      console.log(`/#${item.url}?assisId=${item.assisId}`);
      window.open(`/#${item.url}?assisId=${item.assisId}`, "_Home");

      // this.$router.push({

      //   path: item.url,
      //   query: { key: item.key,assisId:item.assisId }
      // });
    },
    goTarget(href) {
      window.open(href, "_blank");
    },
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
        this.qrUrl = window.location.origin + '/app?deptId=' + this.user.deptId
        console.log("qrUrl", this.qrUrl);
      });
    },
    /** 查询主页路由列表 */
    getCfgList() {
      this.loading = true;
      // this.configList = response.rows;

    },
    getCacheList() {
      getCache().then((response) => {
        this.cache = response.data;
        // this.$modal.closeLoading();

        this.usedmemory = echarts.init(this.$refs.usedmemory, "macarons");
        this.usedmemory.setOption({
          tooltip: {
            formatter: "{b} <br/>{a} : " + this.cache.info.used_memory_human,
          },
          series: [
            {
              name: "峰值",
              type: "gauge",
              min: 0,
              max: 1000,
              detail: {
                formatter: this.cache.info.used_memory_human,
              },
              data: [
                {
                  value: parseFloat(this.cache.info.used_memory_human),
                  name: "内存消耗",
                }
              ]
            }
          ]
        });
        window.addEventListener("resize", () => {
          this.usedmemory.resize();
        });
      });
    },
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans",
  "Helvetica Neue",
  Helvetica,
  Arial,
  sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}


.user-avatar {
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 12px;
}


ul.icon-list {
  overflow: hidden;
  list-style: none;
  padding: 0 !important;
  border: 1px solid #eaeefb;
  border-right: 0;
  border-bottom: 0;
}

.icon-list li {
  float: left;
  width: 33.33%;
  text-align: center;
  height: 139px;
  color: #666;
  font-size: 13px;
  border-right: 1px solid #eee;
  border-bottom: 1px solid #eee;
}

.card-icon {
  font-size: 30px;
  color: #a3d3ff;
}


@media (max-width: 1200px) {
  .icon-list li {
    width: 50%;
    height: 139px;
  }

  .icon-list li .mt45 {
    margin-top: 10px;
  }
}

.zhushouDiv {
  width: 100%;
  display: flex;

}

.card-diy {
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid #ebeef5;

  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: #c6e2ff;
  }
}



/* 自定义选中样式 */
.card-diy {
  position: relative;

  &.is-active,
  &.is-checked {
    border-color: #409eff;
    background-color: #f0f8ff;

    &::after {
      content: "";
      position: absolute;
      top: 0;
      right: 0;
      border-top: 20px solid #409eff;
      border-left: 20px solid #409eff;
      border-right: 20px solid #409eff;
      border-bottom: 20px solid #ffffff00;
    }

    &::before {
      content: "✓";
      position: absolute;
      top: -1px;
      right: 12px;
      color: white;
      font-size: 15px;
      font-weight: bold;
      z-index: 1;
    }
  }
}

.card-header {
  display: flex;
  padding: 10px 0;
  min-height: 60px;

  .card-title {
    font-weight: 600;
    font-size: 16px;
    color: #606266;
    writing-mode: vertical-rl;
    /* 关键属性 */

    align-items: center;
    /* 居中对齐 */
    text-align: center;
    /* 文字居中 */
    margin-top: 5px;
    /* 添加顶部间距 */
  }

  .right {
    margin-left: 0;
    /* 重置左边距 */
    margin-top: 5px;
    /* 添加顶部间距 */
  }
}

.card-checked {
  color: #409eff !important;
}
</style>
